{extend name="$base" /}
{block name="resources"}
<style>
.modal-infp-style{width:90%;margin:10px auto;}
.modal-infp-style table{width:100%;}
.modal-infp-style table tr td{border: 1px solid #e5e5e5;padding: 10px;}
.align_left{text-align: left;}
.align_right{text-align: right;}
</style>
{/block}
{block name="main"}
<table class="mytable">
	<tr>
		<th width="20%" style="text-align:left;"><button class="btn-common btn-small" onclick="location.href='{:__URL('ADMIN_MAIN/wchat/addApplet')}';" style="margin:0 5px 0 0 !important;">添加小程序</button></th>
		<th width="10%">
			<input type="text" id = 'search_text' placeholder="请输入小程序名称" class="input-common" />
			<input type="button" onclick="searchData()" value="搜索" class="btn-common" />
		</th>
	</tr>
</table>
<table class="table-class">
		<col style="width: 15%;">
		<col style="width: 15%;">
		<col style="width: 15%;">
		<col style="width: 10%;">
		<col style="width: 35%;">
		<col style="width: 10%;">
	<thead>
		<tr align="center">
			<th class="align_left">名称</th>
			<th class="align_left">appid</th>
			<th class="align_left">appsecret</th>
			<th class="align_center">排序<span class="row-20"></th>
			<th class="align_left">备注</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody id="ajax_list"></tbody>
</table>
{/block}
{block name="script"}
<script type="text/javascript">
function LoadingInfo(page_index) {
	var search_text = $("#search_text").val();
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/wchat/appletList')}",
		data : {
			"page_index" : page_index,
			"page_size" : $("#showNumber").val(),
			"search_text" : search_text
		},
		success : function(data) {
			if (data["data"].length > 0) {
				$(".table-class tbody").empty();
				for (var i = 0; i < data["data"].length; i++) {
					var html = '';
					html += '<tr align="center" class="tr-item">';
                    	html += '<td class="align_left">' + data["data"][i]["applet_name"] + '</td>';
						html += '<td class="align_left">' + data["data"][i]["appid"] + '</td>';
						html += '<td class="align_left">' + data["data"][i]["appsecret"] + '</td>';
						html += '<td class="align_center">' + data["data"][i]["sort"] + '<span class="row-20"></td>';
						html += '<td class="align_left">' + data["data"][i]["remark"] + '<span class="row-20"></td>';
						html += '<td>';
							html += '<a href="javascript:;" onclick="deleteApplet('+data["data"][i]["applet_id"]+');">删除</a>';
							html += '<a href="' + __URL(ADMINMAIN+"/wchat/editApplet?applet_id="+data["data"][i]['applet_id']) + '" target="_blank">修改</a>';
						html += '</td>';
					html += '</tr>';
					$('#ajax_list').append(html);
				}
			} else {
				var html = '<tr align="center"><td colspan="5">暂无符合条件的数据记录</td></tr>';
				$(".table-class tbody").html(html);
			}
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
		}
	});
}

function searchData(){
	LoadingInfo(1);
}

function deleteApplet(applet_id){
    $( "#dialog" ).dialog({
        buttons: {
            "确定": function() {
                $.ajax({
                    type:"post",
                    url : "{:__URL('ADMIN_MAIN/wchat/deleteApplet')}",
                    data : { "applet_id" : applet_id},
                    dataType : "json",
                    success : function(data) {
                        if (data["code"] > 0) {
                            showMessage('success', data["message"]);
                        }else{
                            showMessage('error', data['message']);
                        }
                        LoadingInfo(getCurrentIndex(applet_id, '#ajax_list', 'tr[class="tr-item"]'));
                    }
                })
                $(this).dialog('close');
            },
            "取消,#f5f5f5,#666": function() {
                $(this).dialog('close');
            },
        },
        contentText:"删除不可逆,请谨慎操作,确定要删除小程序吗？",
    });
}
</script>
{/block}